package com.github_dididipapa.common.config;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;

/**
 * @description: Redis 在 Spring-Cache 的配置
 * @author: dididi_papa
 * @email: mitis1624087624@gmail.com
 * @date: 2025/08/09  17:22
 */

public class CacheConfiguration {


    RedisCacheConfiguration redisCacheConfiguration() {
        RedisCacheConfiguration cache = RedisCacheConfiguration.defaultCacheConfig();

        return cache.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new FastJsonRedisSerializer<Object>(Object.class)));
    }
}
